package com.example.perpetualcalendar.ui.fragment.account;


import android.content.ContentValues;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.perpetualcalendar.domain.entity.Account;

import org.litepal.LitePal;


public class AccountViewModel extends ViewModel{

    private MutableLiveData<String> mName;
    private Boolean sign;
    private Account aTrue;

    public AccountViewModel() {
        mName = new MutableLiveData<>();
        getAccount();
    }

    public LiveData<String> getMName(){
        return mName;
    }

    public Boolean getSign(){
        return sign;
    }

    public void getAccount(){
        mName.setValue("点击登录");
        sign=true;
        aTrue = LitePal.where("state = ?", "true").findFirst(Account.class);
        if(aTrue !=null){
            sign=false;
            mName.setValue(aTrue.getName());
        }
    }
    public void exit(){
        if(aTrue!=null){
            ContentValues values = new ContentValues();
            values.put("state",false);
            LitePal.update(Account.class
                    ,values
                    ,aTrue.getId());
            getAccount();
        }
    }
}